<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>找出被修改过的数字</title>
</head>
<body>
    <p>假设背景是寻找数组中被修改的数字或者元素，我使用代理的方式来监听数组中元素的变化，并将变化的最后数值和次数储存在额外空间中</p>
    <script>
        function diffForArray(arr) {
            const saveModifyNum={

            }
            const watchNumChangeProxy=new Proxy(arr,{
                set:function(target,key,value){
                    let {count} = Reflect.get(saveModifyNum,target[key])||{count:0,value};
                    ++count;
                    return Reflect.set(saveModifyNum,target[key],{
                        count,
                        value
                    });    
                }
            })
            watchNumChangeProxy[0]=2;
            watchNumChangeProxy[0]=3;
            watchNumChangeProxy[0]=4;
            watchNumChangeProxy[0]=5;
            watchNumChangeProxy[0]=6;
            console.log('diffForArray-result', saveModifyNum);
            console.log('watchNumChangeProxy-result', watchNumChangeProxy);
        }

        const arr =[1,2,3,4,5,6,7,8,89,9,9,9,9,99];
        this.diffForArray(arr);
    </script>
</body>
</html>